package com.defysoft.waukidsbus;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

public class JsonParser implements PublicConstant, Data_Type, Custom_Data_Type {
	public static ArrayList<BC_GOBUS> AttendSelectMember(String message) {

		ArrayList<BC_GOBUS> list = new ArrayList<BC_GOBUS>();
		BC_GOBUS bcGobus;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bcGobus = new BC_GOBUS();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Gob_Code")) {
						bcGobus.PK_Gob_Code = jsonObject.getInt("PK_Gob_Code");
					}
					if (jsonObject.has("FK_Sch_Gob_Code")) {
						bcGobus.FK_Sch_Gob_Code = jsonObject
								.getInt("FK_Sch_Gob_Code");
					}
					if (jsonObject.has("Gob_Name")) {
						bcGobus.Gob_Name = jsonObject.getString("Gob_Name");
					}
				}
				list.add(bcGobus);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}
	
	public static ArrayList<BC_BACKBUS> AttendEndSelectMember(String message) {

		ArrayList<BC_BACKBUS> list = new ArrayList<BC_BACKBUS>();
		BC_BACKBUS bcbBackbus;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				bcbBackbus = new BC_BACKBUS();
				if (jsonObject != null) {
					if (jsonObject.has("PK_Bac_Code")) {
						bcbBackbus.PK_Bac_Code = jsonObject.getInt("PK_Bac_Code");
					}
					if (jsonObject.has("FK_Sch_Bac_Code")) {
						bcbBackbus.FK_Sch_Bac_Code = jsonObject
								.getInt("FK_Sch_Bac_Code");
					}
					if (jsonObject.has("Bac_Name")) {
						bcbBackbus.Bac_Name = jsonObject.getString("Bac_Name");
					}
				}
				list.add(bcbBackbus);
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}
	
	

	public static ArrayList<StartBus> StartScanMode(String message) {

		ArrayList<StartBus> list = new ArrayList<StartBus>();
		StartBus startBus;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				startBus = new StartBus();
				if (jsonObject != null) {
					if (jsonObject.has("Gob_Stu_Order")) {
						startBus.Gob_Stu_Order = jsonObject.getString("Gob_Stu_Order");
					}
					if (jsonObject.has("Gob_Stu_Address")) {
						startBus.Gob_Stu_Address = jsonObject.getString("Gob_Stu_Address");
					}
					if (jsonObject.has("stu_code")) {
						startBus.stu_code = jsonObject.getString("stu_code");
					}
					if (jsonObject.has("stu_name")) {
						startBus.stu_name = jsonObject.getString("stu_name");
					}
					if (jsonObject.has("bea_id")) {
						startBus.bea_id = jsonObject.getString("bea_id");
					}
				}
				if (startBus.stu_code == null || startBus.stu_code.equals("")
						|| startBus.stu_code.equals("null")) {
				} else {
					list.add(startBus);
				}
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}
	
	public static ArrayList<EndBus> EndScanMode(String message) {

		ArrayList<EndBus> list = new ArrayList<EndBus>();
		EndBus endBus;
		JSONObject jsonObject;
		try {
			JSONArray jsonArray = new JSONArray(message);
			for (int i = 0; i < jsonArray.length(); i++) {
				jsonObject = jsonArray.getJSONObject(i);
				endBus = new EndBus();
				if (jsonObject != null) {
					if (jsonObject.has("Bac_Stu_Order")) {
						endBus.Bac_Stu_Order = jsonObject.getString("Bac_Stu_Order");
					}
					if (jsonObject.has("Bac_Stu_Address")) {
						endBus.Bac_Stu_Address = jsonObject.getString("Bac_Stu_Address");
					}
					if (jsonObject.has("stu_code")) {
						endBus.stu_code = jsonObject.getString("stu_code");
					}
					if (jsonObject.has("stu_name")) {
						endBus.stu_name = jsonObject.getString("stu_name");
					}
					if (jsonObject.has("bea_id")) {
						endBus.bea_id = jsonObject.getString("bea_id");
					}
				}
				if (endBus.stu_code == null || endBus.stu_code.equals("")
						|| endBus.stu_code.equals("null")) {
				} else {
					list.add(endBus);
				}
			}
		} catch (Exception e) {
			return list;
		}
		return list;
	}
}// CLASS_END
